package com.itheima.common.exception.advice;

import com.itheima.common.exception.NcException;
import com.itheima.common.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@ResponseBody
@ControllerAdvice
public class BasicExceptionHandler {


    /**
     * 处理自定义异常
     * @return
     */
    @ExceptionHandler(NcException.class)
    public Result handlerNcException(NcException exception){
        return new Result(false, exception.getStatus(), exception.getMessage());
    }

    /**
     * 处理运行时异常
     * @param exception
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public Result handlerNcException(RuntimeException exception){
        return new Result(false, 500, exception.getMessage());
    }

    /**
     * 处理运行时异常
     * @param exception
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result handlerNcException(Exception exception){
        return new Result(false, 500, exception.getMessage());
    }
}
